import boss from './canvas/boss'
import steel from './canvas/steel'
import wall from './canvas/wall'
import water from './canvas/water'
import config from './config'

export default {
  // 画布边缘检测
  isCanvasTouch(
    x: number,
    y: number,
    width: number = config.model.width,
    height: number = config.model.height
  ): boolean {
    return (
      x < 0 ||
      x + width > config.canvas.width ||
      y < 0 ||
      y + height > config.canvas.height
    )
  },

  // 模型碰撞检测,返回碰撞到的模型
  isModelTouch(
    x: number,
    y: number,
    width: number = config.model.width,
    height: number = config.model.height,
    models: IModel[] = [
      ...wall.models,
      ...steel.models,
      ...water.models,
      ...boss.models,
    ]
  ): IModel | undefined {
    return models.find((model) => {
      const state =
        x + width <= model.x ||
        x >= model.x + model.width ||
        y + height <= model.y ||
        y >= model.y + model.height

      return !state
    })
  },
}
